let file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
file.append(databaseName);
return this.STORAGE.openDatabase(file);
},
createTables : function() {
if (!this.DB.tableExists('items'))
{
this.DB.executeSimpleSQL("CREATE TABLE items (item_id INTEGER NOT NULL , unique_id INTEGER NOT NULL, url VARCHAR NOT NULL , title VARCHAR NOT NULL , time_updated INTEGER NOT NULL , offline_web INTEGER NOT NULL , offline_text INTEGER NOT NULL, percent INTEGER NOT NULL )");
this.DB.executeSimpleSQL("CREATE INDEX item_idIndex ON items ( item_id )");
this.DB.executeSimpleSQL("CREATE UNIQUE INDEX url ON items ( url )");
this.DB.executeSimpleSQL("CREATE INDEX time_updated ON items ( time_updated )");
this.DB.executeSimpleSQL("CREATE INDEX percent ON items ( percent )");
}
if (!this.DB.tableExists('tags'))
{
this.DB.executeSimpleSQL("CREATE TABLE tags (item_id INTEGER NOT NULL , tag VARCHAR NOT NULL , PRIMARY KEY (item_id, tag))");
}
if (!this.DB.tableExists('scroll'))
{
this.DB.executeSimpleSQL("CREATE TABLE scroll (item_id INTEGER NOT NULL, view INTEGER NOT NULL, section INTEGER NOT NULL, page INTEGER NOT NULL, node_index INTEGER NOT NULL, percent INTEGER NOT NULL, time_updated INTEGER NOT NULL, PRIMARY KEY (item_id, view))");
}
if (!this.DB.tableExists('resolver'))
{
this.DB.executeSimpleSQL("CREATE TABLE resolver (item_id INTEGER NOT NULL , url VARCHAR)");
}
if (!this.DB.tableExists('sync_queue'))
{
this.DB.executeSimpleSQL("CREATE TABLE sync_queue (type VARCHAR NOT NULL, url VARCHAR NOT NULL, PRIMARY KEY(url, type))");
}
if (!this.DB.tableExists('assets'))
{
this.DB.executeSimpleSQL("CREATE TABLE assets (asset_domain VARCHAR NOT NULL)");
}
if (!this.DB.tableExists('assets_items'))
{
this.DB.executeSimpleSQL("CREATE TABLE assets_items (asset_domain VARCHAR NOT NULL , item_id INTEGER NOT NULL , PRIMARY KEY (asset_domain, item_id))");
this.DB.executeSimpleSQL("CREATE INDEX item_id_lookup ON assets_items ( item_id )");
}
if (!this.DB.tableExists('vars'))
{
this.DB.executeSimpleSQL("CREATE TABLE vars (unique_id INTEGER NOT NULL)");
this.DB.executeSimpleSQL("INSERT INTO vars (unique_id) VALUES (0)");
}
},
dumpAndReinstallDatabase : function()
{
// Drop all tables - ideally we'd just remove the file but this.DB.close() results in an error, so we do it the long way
let sql = "select name from sqlite_master where type = 'table'";
let storeSecurely = this.PREFS.getBool('storeSecurely');
let hasMasterPassword = this.hasMasterPassword();
let promptedAboutMasterPass = this.PREFS.getBool('promptedAboutMasterPass');
if (storeSecurely && hasMasterPassword && !promptedAboutMasterPass)
{
let check = {value:false};
this.PROMPT.alertCheck( this.getMainWindow(), "Master Passwords and Read It Later",
"Read It Later stores your username and password securely in Firefox's password manager. If you have a master password enabled this means you will be prompted every time RIL auto-syncs. You can disable this under the advanced options by opting to disable storing your RIL account login securely.",
"Do not tell me again",
check);
if (check.value)
{
this.PREFS.set('promptedAboutMasterPass', true);
}
}
if (storeSecurely)
{
// Find users for the given parameters
var logins = this.LOGIN.findLogins({}, this.loginInfo.hostname, this.loginInfo.formSubmitURL, this.loginInfo.httprealm);
return logins[0]; // only storing one, so just return the first
}
else
{
let username = this.PREFS.get('username');
let password = this.PREFS.get('password');
if (!username || !password) return;
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",